<template>
  <div class="calendar-cell" @click="handleClickBtnOpenDialog">
    <div class="calendar-cell-bd">
      <div class="div-1">{{ date.getDate() }}</div>
      <div class="div-3" v-if="itemData.length > 0">
        <el-popover placement="top" :width="400" trigger="hover">
          <template #reference>
            <el-result class="result" :sub-title="itemData.length + '条记录'">
              <template #icon>
                <el-icon :size="36" color="#409EFF"><Flag /></el-icon>
              </template>
            </el-result>
          </template>
          <el-space direction="vertical" style="width: 100%" fill="fill">
            <el-card v-for="item in itemData" style="width: 100%" :key="item" shadow="never">
              <el-row :gutter="10" style="width: 100%">
                <el-col :span="6">开始时间：</el-col>
                <el-col :span="12">{{ item.startTime }}</el-col>
                <el-col :span="6" style="text-align: right">
                  <el-button type="danger" text :icon="RefreshLeft" size="small" @click="handleClickBtnRevoke(item)">撤销</el-button>
                </el-col>
              </el-row>
              <el-row :gutter="10" style="width: 100%">
                <el-col :span="24"> <el-divider class="divider" /></el-col>
              </el-row>
              <el-row :gutter="10" style="width: 100%">
                <el-col :span="6">结束时间：</el-col>
                <el-col :span="18">{{ item.endTime }}</el-col>
              </el-row>
              <el-row :gutter="10" style="width: 100%">
                <el-col :span="24"> <el-divider class="divider" /></el-col>
              </el-row>
              <el-row :gutter="10" style="width: 100%">
                <el-col :span="6">请假事由：</el-col>
                <el-col :span="18">
                  <div class="remark-content">
                    {{ item.remark }}
                  </div>
                </el-col>
              </el-row>
            </el-card>
          </el-space>
        </el-popover>
      </div>
    </div>
  </div>
</template>
<script setup lang="ts">
// import { ref } from 'vue'
import { RefreshLeft, Flag } from '@element-plus/icons-vue'

const emit = defineEmits(['click', 'delete'])

const props = defineProps({
  date: {
    required: true,
    type: Date || null,
    default: () => {},
  },
  itemData: {
    required: true,
    type: (Array as any) || null,
    default: () => [],
  },
})
const handleClickBtnOpenDialog = () => {
  if (props.itemData.length == 0) {
    emit('click', props.date)
  }
}
const handleClickBtnRevoke = (val: any) => {
  emit('delete', val.id)
}
</script>
<style lang="scss" scoped>
.divider {
  margin: 10px 0 !important;
}
.calendar-cell {
  width: 100%;
  height: 100%;
  position: relative;
  .calendar-cell-bd {
    height: 100%;
    width: 100%;
    position: absolute !important;
    .result {
      padding: 0;
    }
  }
  .div-1 {
    font-size: 28px;
    position: relative !important;
    text-align: left;
  }
  .div-3 {
    pointer-events: initial !important;
    text-align: left;
    bottom: 0;
    flex: 1;
    width: 100%;

    div {
      & + div {
        margin-top: 0;
      }
    }
    .remark-content {
      white-space: pre-line;
    }
  }
}
</style>
